﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using MinhTam.DataAccess.Web;
using System.Web.UI.HtmlControls;


public partial class _Default : System.Web.UI.Page
{
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            hienthi_thongtin();
            InitSlideShow();              
         
        }
    }
    private void InitSlideShow()
    {
        string sql = string.Format(@"SELECT ha.ID,'{0}'+ ha.URL_IMAGE URL_IMAGE,REPLACE( ha.URL_LINK,'~/','') URL_LINK
         FROM HINH_ANH ha
        WHERE ha.ALBUM_ID={1} AND ISNULL (ha.IS_HIDEN,'N')<>'Y'
        ORDER BY ISNULL (ha.SAP_XEP,9999)", HelpConstEnum.UPLOAD_IMAGE_FOLDER.Replace("~/", ""), HelpConstEnum.LoaiAlbum.SLIDE_SHOW.GetHashCode());
        DataTable dt = SQLConnectWeb.GetTable(sql);
        image.DataSource = dt;
        image.DataBind();

    }
    public void hienthi_thongtin()
    {
        try
        {

            String sql = @"select TOP 5 a.ten_loai,b.bai_viet_id,b.ten_bai_viet,b.HINH_THUMBNAIL,b.trich_doan
    from loai_bai_viet a
    left join  bai_viet b on a.loai_bai_viet_id = b.loai_bai_viet
    where b.duyet='Y' and a.loai_bai_viet_id={0}
    ORDER BY ISNULL (b.NOI_BAT,'N') DESC,b.NGAY_TAO ASC";

            #region Thông Báo

            
            int typeTB = HelpConstEnum.LoaiBaiViet.THONG_BAO.GetHashCode();
            DataTable tableTB = SQLConnectWeb.GetData(string.Format(sql, typeTB));


            if (tableTB == null || tableTB.Rows.Count == 0 || tableTB.Rows[0]["bai_viet_id"].ToString() == "")
            {
                divThongBao.Visible = false;
                //noidung.Text = "<span class='format-txt'>NỘI DUNG ĐANG ĐƯỢC CẬP NHẬT. XIN CẢM ƠN</span>";
                //hinhdaidien.Visible = false;


            }
            else
            {

                tieudeThongBao.Text = tableTB.Rows[0]["ten_bai_viet"].ToString();
                url_ThongBao_img.HRef = "bvchitiet.aspx?req=" + typeTB + "&id=" + tableTB.Rows[0]["bai_viet_id"];
                url_ThongBao_title.HRef = "bvchitiet.aspx?req=" + typeTB + "&id=" + tableTB.Rows[0]["bai_viet_id"];
                noidungThongBao.Text = tableTB.Rows[0]["trich_doan"].ToString();


                thumbnailThongBao.ImageUrl = HelpConstEnum.UPLOAD_IMAGE_FOLDER + tableTB.Rows[0]["HINH_THUMBNAIL"];
                thumbnailThongBao.Width = 100;

                tableTB.Rows.RemoveAt(0);
                docthemThongBao.DataSource = tableTB;
                docthemThongBao.DataBind();

            }

            #endregion

            #region Tin tức
            int typeTT = HelpConstEnum.LoaiBaiViet.TIN_TUC.GetHashCode();
            DataTable table_tt = SQLConnectWeb.GetData(string.Format(sql, typeTT));



            if (table_tt == null || table_tt.Rows.Count == 0 || table_tt.Rows[0]["bai_viet_id"].ToString() == "")
            {
                noidungTinTuc.Text = HelpConstEnum.EMPTY_CONTENT;
                thumbnailTinTuc.Visible = false;


            }
            else
            {

                tieudeTinTuc.Text = table_tt.Rows[0]["ten_bai_viet"].ToString();
                url_TinTuc_img.HRef = String.Format("bvchitiet.aspx?req={0}&id={1}", typeTT, table_tt.Rows[0]["bai_viet_id"]);
                url_TinTuc_title.HRef = String.Format("bvchitiet.aspx?req={0}&id={1}", typeTT, table_tt.Rows[0]["bai_viet_id"]);
                noidungTinTuc.Text = table_tt.Rows[0]["trich_doan"].ToString();

                thumbnailTinTuc.ImageUrl = HelpConstEnum.UPLOAD_IMAGE_FOLDER + table_tt.Rows[0]["HINH_THUMBNAIL"];
                thumbnailTinTuc.Width = 100;

                table_tt.Rows.RemoveAt(0);
                docthemTinTuc.DataSource = table_tt;
                docthemTinTuc.DataBind();



            }

            #endregion

            #region Lưu bút

            int typeLB = HelpConstEnum.LoaiBaiViet.LUU_BUT_KHACH_HANG.GetHashCode();
            DataTable table_lb = SQLConnectWeb.GetData(string.Format(sql, typeLB));


            if (table_lb == null || table_lb.Rows.Count == 0 || table_lb.Rows[0]["bai_viet_id"].ToString() == "")
            
            {
                noidungLuuBut.Text = HelpConstEnum.EMPTY_CONTENT;
                thumbnailLuuBut.Visible = false;
                

            }
            else
            {

                tieudeLuuBut.Text = table_lb.Rows[0]["ten_bai_viet"].ToString();
                url_LuuBut_img.HRef = "bvchitiet.aspx?req=" + typeLB + "&id=" + table_lb.Rows[0]["bai_viet_id"];
                url_LuuBuu_title.HRef = "bvchitiet.aspx?req=" + typeLB + "&id=" + table_lb.Rows[0]["bai_viet_id"];
                noidungLuuBut.Text = table_lb.Rows[0]["trich_doan"].ToString();

                thumbnailLuuBut.ImageUrl = HelpConstEnum.UPLOAD_IMAGE_FOLDER + table_lb.Rows[0]["HINH_THUMBNAIL"];
                thumbnailLuuBut.Width = 100;

                table_lb.Rows.RemoveAt(0);

                docthemLuuBut.DataSource = table_lb;
                docthemLuuBut.DataBind();



            }

            #endregion
        }
        catch
        {
        }

    }
}
